<style>
    .description { color: green; text-decoration: underline; font-size: 13px; }
    .chosen-container-single .chosen-single { height: 35px; line-height: 35px; padding: 0 0 0 13px; }
    .chosen-container-single .chosen-single div b { background-position: 0 8px; }
    .chosen-container-active.chosen-with-drop .chosen-single div b { background-position: -18px 8px; }
</style>

<form method="post" action="/oss/?r=operation/doDeduct">
    <{include file='../common_params.tpl'}>

    <div class="box box-black">
        <div class="box-body">
            <table class="table table-bordered">
                <colgroup>
                    <col style="width: 20%;"></col>
                    <col style="width: 80%;"></col>
                </colgroup>

                <tr>
                    <th class="th-label"></th>
                    <td>
                        <label><input type="radio" name="type" value="item" class="type-radio simple" checked /> 道具</label>
                        <label><input type="radio" name="type" value="gold" class="type-radio simple" /> 金币</label>
                    </td>
                </tr>

                <tr>
                    <th class="th-label">角色名称</th>
                    <td>
                        <input type="text" name="role_name" class="form-control" placeholder="要扣除的用户的角色名称" />
                    </td>
                </tr>

                <tr class="tr-item">
                    <th class="th-label">道具</th>
                    <td>
                        <select class="sel-item-type form-control inline">
                            <option value="">--道具类型--</option>
                            <{foreach from=$itemList item=item key=key}>
                            <option value="<{$key}>"><{$item}></option>
                            <{/foreach}>
                        </select>

                        <select name="prop_id" style="width: 280px;" class="sel-item-list form-control inline">
                            <option value="">--请先选择道具类型--</option>
                        </select>

                        <input type="text" name="prop_num" class="form-control inline" placeholder="道具数量" />
                    </td>
                </tr>

                <tr class="tr-item">
                    <th class="th-label">道具唯一ID</th>
                    <td>
                        <input type="text" name="only_id" class="form-control" placeholder="拥有道具唯一ID,则优先扣除该道具,否则按照上方选择的道具扣除" />
                    </td>
                </tr>

                <tr class="tr-gold">
                    <th class="th-label">金币类型</th>
                    <td>
                        <select name="gold_id" class="form-control inline">
                            <option value="">--金币类型--</option>
                            <{html_options options=$goldList}>
                        </select>
                        <input type="text" name="gold_num" class="form-control inline" placeholder="金币数量" />
                    </td>
                </tr>

                <tr>
                    <th class="th-label">扣除原因</th>
                    <td>
                        <textarea class="form-control" name="reason"></textarea>
                    </td>
                </tr>
            </table>
        </div>

        <div class="box-footer">
            <button type="submit" class="btn btn-default pull-right">确认</button>
            <div style="clear: both;"></div>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(function(){
        var itemUrl = '<{$itemUrl nofilter}>';

        $(".sel-item-list").chosen();
        $(".sel-item-type").live('change', function(){
            var type = $(this).val(),
                    itemSelect = $(this).next('.sel-item-list');

            itemSelect.val('').find('option.item').remove();
            itemSelect.trigger("chosen:updated");
            if(type){
                $.getJSON(itemUrl, { 'type':type }, function(rs){
                    for(var i in rs){
                        itemSelect.append('<option class="item" value="'+rs[i]['id']+'">'+rs[i]['id']+' - '+rs[i]['name']+'</option>');
                    }
                    itemSelect.trigger("chosen:updated");
                });
            }
        });


        $(".type-radio").change(function(){
            var type = $(".type-radio:checked").val();

            $(".tr-item,.tr-gold").hide().filter(".tr-"+type).show();
        }).change();

    });
</script>